﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookLink.Models
{
    public class Book
    {
        public int Id { get; set; }
        [StringLength(500)]
        [Required]
        [Display(Name = "书籍名称")]
        public string Title { get; set; }  // 书籍名称

        //[DataType(DataType.Date)]
        //[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [StringLength(10)]
        [Display(Name = "出版日期")]
        public string ReleaseDate { get; set; }  // 出版日期
        [Display(Name = "创建时间")]
        [DataType(DataType.DateTime)]
        public DateTime CreationAt { get; set; } = DateTime.Now; // 创建时间
        [StringLength(100)]
        [Required]
        [Display(Name = "分类")]
        public string Genre { get; set; }  // 分类 只按书籍的主要编程语言分类
        [StringLength(1024)]
        [Display(Name = "下载链接")]
        public string Dowloadlink { get; set; } // 下载链接
        public string DowloadPath
        {
            get
            {
                if (!string.IsNullOrEmpty(Dowloadlink))
                {
                    return Dowloadlink.Length > 30 ? Dowloadlink.Substring(0, 30) + "..." : Dowloadlink;
                }
                return "";
            }
        }

        //[StringLength(1024)]
        //[Required(AllowEmptyStrings =true)]
        [Display(Name = "书籍封面")]
        public string? ImageUrl { get; set; }  // 封面地址

        [Display(Name = "作者")]
        [StringLength(512)]
        public string Author { get; set; } // 作者
        [Display(Name = "下载次数")]
        public int DownloadCount { get; set; }

        [Display(Name = "删除标记")]
        public int IsDeleted { get; set; } // 删除标记 
        [Display(Name = "是否可见")]
        public bool IsVisible { get; set; } = true; // 标记是否可见
    }
}
